//
// Created by miaomiaole on 2024/6/22.
//

#include <iostream>
#include "Base.h"
#include <malloc.h>
#include <memory.h>

using namespace std;

SpreadSheetCell::SpreadSheetCell(double initvalue) : initValue(initvalue) {
    cout << "SpreadSheetCell generate" << "initvalue:" << initvalue << endl;
}

SpreadSheetCell::~SpreadSheetCell() {

    std::cout << "destroy SpreadSheetCell" << "initValue :" << initValue <<
              std::endl;


}

void SpreadSheetCell::display() {
    std::cout << "Display function called  initvalue :" << std::endl;
}

SpreadSheetCell::SpreadSheetCell(double initvalue, std::string variable_name) :
        variable_name(variable_name), initValue(initvalue) {
    cout << "second generate SpreadSheetCell  initvalue:" << initvalue << "variable_name:" << variable_name << endl;
}

// 拷贝构造(深拷贝）
SpreadSheetCell::SpreadSheetCell(SpreadSheetCell *src) : initValue(src->initValue),
                                                         variable_name(src->variable_name) {

    cout << "copy constructor SpreadSheetCell  st initValue:" << this->initValue << "variable_name:"
         << this->variable_name
         << endl;
}

// 右值引用构造
SpreadSheetCell::SpreadSheetCell(const SpreadSheetCell &&src) : initValue(src.initValue),
                                                                variable_name(src.variable_name) {
    cout << "second copy constructor SpreadSheetCell  st initValue:" << this->initValue << "variable_name:"
         << this->variable_name
         << endl;
}

// 赋值函数 （重写 = 操作符）
SpreadSheetCell &SpreadSheetCell::operator=(SpreadSheetCell &rhs) {
    return *this;
}

double SpreadSheetCell::getInitValue() const {
    return initValue;
}

void SpreadSheetCell::setInitValue(double initValue) {
    SpreadSheetCell::initValue = initValue;
}

const string &SpreadSheetCell::getVariableName() const {
    return variable_name;
}

void SpreadSheetCell::setVariableName(const string &variableName) {
    variable_name = variableName;
}

//友元方法
void Driver::drive(Car &car) {
    if (car.fuel > 0) {
        std::cout << "Driving the car!" << std::endl;
        car.fuel -= 1;  // 消耗燃料
    } else {
        std::cout << "Not enough fuel!" << std::endl;
    }
}

Base::~Base() {
    std::cout << "destroy Base" << std::endl;
}

Base::Base() {
    cout << "generate base " << endl;
}

Derived::~Derived() {
    delete[] m_string;
    std::cout << "destroy Derived" << std::endl;
}

something::something() {
    cout << "2" << endl;
}

something::~something() {
    cout << "2" << endl;
}

base::base() {
    cout << "1" << endl;;
}

base::~base() {
    cout << "1" << endl;
}

derived::derived() {
    cout << "3" << endl;;
}

derived::~derived() {
    cout << "3" << endl;
}

Point &Point::operator++() {
    _x++;
    _y++;
    return *this;
}

Point Point::operator++(int) {
    Point temp = *this;
    ++*this;
    return temp;
}

// 内部类实现
class my_class_impl::impl {

};

void *Blanks::operator new(size_t stAllocateBlock, char chInit) {
    void *blanks_p = malloc(stAllocateBlock);
    // 内存分配成功
    if (blanks_p != 0) {
        memset(blanks_p, chInit, stAllocateBlock);
    }
    return blanks_p;
}

void Blanks::operator delete(void *) {

}

void Blanks::operator delete(void *, size_t) {

}
void lambda_func(){
    // [] 捕获上下文变量
    // mutable 运行修改[] 中捕获的变量
    auto add_lambda = [](int a, int b) mutable {
        return a + b;
    };
    auto func_A = [](my_class_2 *mc) {
        mc->num = 3;
    };

    auto func_B = [](my_class_2 mc) {
        mc.num = 21;
        mc.print();
    };
}